#!/bin/bash

top_builddir=@top_builddir@
srcdir=@srcdir@

function clean()
{
    for f in $* ; do 
	[ -f $f ] && rm $f ; 
    done
}

function generate_random_string()
{
    local size=$1

    awk -v size=$size '
BEGIN { chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ       \n\n\n"; } 
END { for (i=0; i < size; i++) {n = rand() *length(chars); printf "%c", substr(chars, n, 1); } printf("\n"); }
' < /dev/null
}

function run_perseus_test_1()
{
    local size=$2
    local file=$1.$size

    set -x
    clean $file $file.decoded
    generate_random_string $size > "$file"
    ${top_builddir}/tests/perseus_test $file
    diff $file $file.decoded
    STATUS=$?
    exit $STATUS
}

function run_perseus_test_2()
{
    local size=$1

    set -x
    TEST=$(generate_random_string $size)
    RES=$(${top_builddir}/tests/perseus_test2 "$TEST")
    if [ "$RES" != "$TEST" ] ; then
	echo "< $TEST" 
	echo "> $RES" 
	exit 1
    fi
    exit 0
}
